<template>
  <el-tabs v-model="activeName">
    <el-tab-pane :label="'全部帖子('+postinfos.length+')'" name="post">
      <div class="post_list" v-for="(item,index) in postinfos" :key="index">
        <router-link :to="{path:'/home/show/',query:{id:item._id}}" @click.native="read(item._id)">
          <span>{{item.title}}</span>
          <div>发布于{{item.pubDate}}</div>
          <el-badge :value="item.noRead+'条新评论'" type="danger" v-show="item.noRead"></el-badge>
        </router-link>
      </div>
    </el-tab-pane>
    <el-tab-pane :label="'全部评论('+postreplies.length+')'" name="second">
      <div class="post_list" v-for="(item,index) in postreplies" :key="index">
        <router-link :to="{path:'/home/show/',query:{id:item.postId}}">
          <span>{{item.postTitle}}</span>
          <div>评论于{{item.commDate}}</div>
          <div
            style="width:100px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis"
          >{{item.content}}</div>
          <el-badge :value="item.praiseCount" type="primary"></el-badge>
        </router-link>
      </div>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
export default {
  props: ['postinfos', 'postreplies', 'username'],
  data() {
    return {
      activeName: 'post'
    }
  },
  methods: {
    // 读取时将通知未读改为已读
    async read(_id) {
      this.comm.noticeRead(this.username, _id, 'postId', 'comment', 1, this)
    }
  },
  created() {}
}
</script>
<style lang="less" scoped>
.el-tabs {
  .title {
    display: flex;
    align-items: center;
    margin-top: 10px;
  }
  .post_list {
    margin-top: 0;
    a {
      display: flex;
      width: 100%;
      height: 35px;
      font-size: 16px;
      line-height: 35px;
      border-bottom: 1px solid #e9e9e9;
      cursor: pointer;
      .el-badge {
        margin-left: auto;
        margin-top: 5px;
      }
      span {
        margin-left: 10px;
        font-size: 15px;
      }
      > div {
        margin-left: 30px;
        font-size: 12px;
        color: #999;
      }
    }
    a:hover {
      background-color: #f4f4f5;
    }
  }
}
</style>
